package ide.ccf.ccproject.wizards;

import ide.ccf.ccproject.ProjectPlugin;
import ide.ccf.ccproject.data.GenerateCPK;
import ide.ccf.ccproject.preferences.PreferenceConstants;
import ide.ccf.ccproject.translate.Message;
import ide.ccf.ccproject.wizards.pages.ExportSelectFolderWizardPage;
import ide.ccf.ccproject.wizards.pages.ExportSetInfoWizardPage;
import ide.ccf.ccproject.wizards.pages.ExportSetInfoWizardPage;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;


public class ExportCpkWizard extends Wizard implements IExportWizard,
		IExecutableExtension {
	ExportSelectFolderWizardPage mainPage;
	public static ExportSetInfoWizardPage setInfoPage;
	IWorkbench workbench;
	IConfigurationElement configuration;

	/**
	 * 初始化
	 */
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench;
		setWindowTitle(Message.ExportCpkWizard_0);
		setNeedsProgressMonitor(true);
		mainPage = new ExportSelectFolderWizardPage(Message.ExportCpkWizard_1);
		setInfoPage = new ExportSetInfoWizardPage(Message.ExportCpkWizard_11);
	}

	public void setInitializationData(IConfigurationElement config, String propertyName,
			Object data) throws CoreException {
		configuration = config;

	}
	
	/**
	 * 添加页面到向导
	 */
    public void addPages() 
    {
        super.addPages(); 
        addPage(mainPage);     
        addPage(setInfoPage);
    }
    
	@SuppressWarnings("deprecation")
	@Override
	public boolean performFinish() {
		if(ExportSelectFolderWizardPage.ccffoldername != null &&
				ExportSelectFolderWizardPage.ccffoldername.getText() != null)
		{
			IPreferenceStore store = ProjectPlugin.getDefault().getPreferenceStore();
			store.setValue(PreferenceConstants.CCF_PATH, ExportSelectFolderWizardPage.ccffoldername.getText().trim());
		}
		GenerateCPK widget = new GenerateCPK(Display.getCurrent().getActiveShell());
		widget.performFinish();
		return true;
	}
	
	
}
